package vistas;

import controladores.Controlador;
import javax.swing.JOptionPane;


public class VentanaCreacionPartida extends javax.swing.JFrame implements InterfazCreacionPartida {

    /**
     * Creates new form VentanaCreacionPartida
     */
    public VentanaCreacionPartida() {
        initComponents();
        setLocationRelativeTo(null);
        
        // Agrupo los botones que permiten seleccionar el nivel en un grupo
        niveles.add(nivelFacil);
        niveles.add(nivelModerado);
        niveles.add(nivelDificil);
        
        // Agrupo los botones que permiten seleccionar el tipo de vehiculo en
        // otro grupo
        vehiculos.add(vehiculoMoto);
        vehiculos.add(vehiculoCuatroPorCuatro);
        vehiculos.add(vehiculoAuto);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        niveles = new javax.swing.ButtonGroup();
        vehiculos = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        volver = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        saludo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        nivelFacil = new javax.swing.JRadioButton();
        nivelModerado = new javax.swing.JRadioButton();
        nivelDificil = new javax.swing.JRadioButton();
        vehiculoAuto = new javax.swing.JRadioButton();
        vehiculoCuatroPorCuatro = new javax.swing.JRadioButton();
        vehiculoMoto = new javax.swing.JRadioButton();
        jLabel3 = new javax.swing.JLabel();
        jugar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Creacion de Partida");
        setPreferredSize(new java.awt.Dimension(763, 400));
        setResizable(false);

        jPanel1.setBackground(java.awt.Color.black);

        volver.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        volver.setText("Volver");

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jLabel1.setForeground(java.awt.Color.white);
        jLabel1.setText("Nueva Partida");

        saludo.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        saludo.setForeground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(107, 107, 107)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(volver, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(volver, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saludo, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel2.setText("Nivel");

        nivelFacil.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        nivelFacil.setText("Facil");
        nivelFacil.setActionCommand("Nivel facil");

        nivelModerado.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        nivelModerado.setText("Moderado");
        nivelModerado.setActionCommand("Nivel moderado");

        nivelDificil.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        nivelDificil.setText("Dificil");
        nivelDificil.setActionCommand("Nivel dificil");

        vehiculoAuto.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        vehiculoAuto.setText("Auto");
        vehiculoAuto.setActionCommand("Vehiculo auto");

        vehiculoCuatroPorCuatro.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        vehiculoCuatroPorCuatro.setText("4x4");
        vehiculoCuatroPorCuatro.setActionCommand("Vehiculo cuatro por cuatro");

        vehiculoMoto.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        vehiculoMoto.setText("Moto");
        vehiculoMoto.setActionCommand("Vehiculo moto");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel3.setText("Vehiculo");

        jugar.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        jugar.setText("Jugar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(333, 333, 333)
                        .addComponent(jugar)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(67, 67, 67)
                .addComponent(jLabel2)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nivelDificil)
                    .addComponent(nivelModerado)
                    .addComponent(nivelFacil))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(vehiculoAuto)
                    .addComponent(vehiculoMoto)
                    .addComponent(vehiculoCuatroPorCuatro))
                .addGap(30, 30, 30)
                .addComponent(jLabel3)
                .addGap(39, 39, 39))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(vehiculoMoto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(vehiculoCuatroPorCuatro)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(vehiculoAuto))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nivelFacil)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nivelModerado)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nivelDificil)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 3, Short.MAX_VALUE)
                .addComponent(jugar)
                .addGap(28, 28, 28))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaCreacionPartida.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaCreacionPartida.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaCreacionPartida.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaCreacionPartida.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaCreacionPartida().setVisible(true);
            }
        });
    }
    
    // Métodos de InterfazVista
    @Override
    public void setControlador(Controlador controlador) {
        volver.addActionListener(controlador);
        jugar.addActionListener(controlador);
        nivelFacil.addActionListener(controlador);
        nivelModerado.addActionListener(controlador);
        nivelDificil.addActionListener(controlador);
        vehiculoMoto.addActionListener(controlador);
        vehiculoCuatroPorCuatro.addActionListener(controlador);
        vehiculoAuto.addActionListener(controlador);
    }
    
    
    @Override
    public void arrancar() {
        // Visualizo la ventana
        setVisible(true);
    }
    
    
    @Override
    public void cerrar () {
        dispose();
    }
    
    // Métodos de InterfazCreacionPartida
    @Override
    public void setSaludo (String string) {
        saludo.setText("Hola "+string);
    }
    
    @Override
    public int getNivel () {
        if (nivelFacil.isSelected()) return 1;
        else if (nivelModerado.isSelected()) return 2;
        else if (nivelDificil.isSelected()) return 3;
        else return 0;
    }
    
    @Override
    public String getVehiculo () {
        if (vehiculoMoto.isSelected()) return "Moto";
        else if (vehiculoCuatroPorCuatro.isSelected()) return "Cuatro Por Cuatro";
        else if (vehiculoAuto.isSelected()) return "Auto";
        else return "ERROR";
    }
    
    @Override
    public void mostrarMensajeDeError () {
        JOptionPane.showMessageDialog (this, 
                "La seleccion no es correcta. Debe seleccionar un nivel y un vehiculo para continuar.");
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton jugar;
    private javax.swing.JRadioButton nivelDificil;
    private javax.swing.JRadioButton nivelFacil;
    private javax.swing.JRadioButton nivelModerado;
    private javax.swing.ButtonGroup niveles;
    private javax.swing.JLabel saludo;
    private javax.swing.JRadioButton vehiculoAuto;
    private javax.swing.JRadioButton vehiculoCuatroPorCuatro;
    private javax.swing.JRadioButton vehiculoMoto;
    private javax.swing.ButtonGroup vehiculos;
    private javax.swing.JButton volver;
    // End of variables declaration//GEN-END:variables
}
